package com.ruoyi.ice.domain;

import com.ice.core.annotation.IceNode;
import com.ice.core.context.IceRoam;
import com.ice.core.leaf.roam.BaseLeafRoamFlow;
import com.ruoyi.common.utils.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;

@Data
@EqualsAndHashCode(callSuper = true)
@IceNode(name = "字符串探针节点", desc = "用于探测roam中是否包含目标字符串")
public class StringFlow extends BaseLeafRoamFlow {

    private String string;

    private String key;


    @Override
    protected boolean doRoamFlow(IceRoam roam) {

        Object value = roam.getMulti(key);

        if(value == null) {
            return false;
        }

        if(StringUtils.isEmpty(string))
            return false;

        String str = String.valueOf(value);

        //valuestr[] 用 , 分割 str
        String[] valueStr = string.split(",");

        //判断 valuestr 是否包含 string
        for (String s : valueStr) {
            if (s.equals(str)) {
                return true;
            }
        }

        return false;

    }
}
